package com.xyht.sca_s.student_manage_system.modules.meeting.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.meeting.entity.req.SmsPredetermineApplyAllowReq;
import com.xyht.sca_s.student_manage_system.modules.meeting.entity.req.SmsPredetermineApplyReq;
import com.xyht.sca_s.student_manage_system.modules.meeting.service.SmsMeetingRoomPredetermineApplyService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 会议室预定申请表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-08-03
 */
@RestController
@SecretBody
@RequestMapping("/meetingRoomApply")
public class SmsMeetingRoomPredetermineApplyController {
    @Resource
    private SmsMeetingRoomPredetermineApplyService smsMeetingRoomPredetermineApplyService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty(value = "提交预定申请")
    @PostMapping("/submit")
    public ResponseResult submitPredetermineApply(@RequestBody SmsPredetermineApplyReq req, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsMeetingRoomPredetermineApplyService.submitPredetermineApply(req, userId);
    }

    @ApiModelProperty(value = "撤销预定申请")
    @PostMapping("/cancel")
    public ResponseResult cancelPredetermineApply(@RequestBody SmsPredetermineApplyReq cancelReq, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsMeetingRoomPredetermineApplyService.cancelPredetermineApply(cancelReq, userId);
    }

    @ApiModelProperty(value = "审批列表")
    @GetMapping("/list")
    public ResponseResult getAssetPredetermineApplyList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                        @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                        @RequestParam(value = "applyType") Integer applyType,
                                                        HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsMeetingRoomPredetermineApplyService.getPredetermineApplyList(userId, applyType, pageNum, pageSize);
    }

    @ApiModelProperty(value = "审批详情")
    @GetMapping("/detail")
    public ResponseResult getPredetermineApplyDetail(@RequestParam(value = "applyId") String applyId, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsMeetingRoomPredetermineApplyService.getPredetermineApplyDetail(applyId, userId);
    }

    @ApiModelProperty(value = "审批")
    @PostMapping("/allow")
    public ResponseResult allowPredetermineApply(@RequestBody SmsPredetermineApplyAllowReq allowReq, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsMeetingRoomPredetermineApplyService.allowPredetermineApply(allowReq, userId);
    }

    @ApiModelProperty(value = "展示指定日期会议室列表及时间")
    @GetMapping("/listMeetingRoomByTime")
    public ResponseResult listMeetingRoomByTime(@RequestParam(value = "date") String date,
                                                @RequestParam(value = "buildingId", required = false) String buildingId,
                                                @RequestParam(value = "capacity", required = false) Integer capacity,
                                                @RequestParam(value = "searStr", required = false) String searStr) {
        return smsMeetingRoomPredetermineApplyService.listMeetingRoomByTime(date, buildingId, capacity, searStr);
    }

    @ApiModelProperty(value = "展示指定会议室列表及时间细节")
    @GetMapping("/listMeetingRoomByTimeDetail")
    public ResponseResult listMeetingRoomByTimeDetail(@RequestParam(value = "date") String date,
                                                      @RequestParam(value = "id") String id) {
        return smsMeetingRoomPredetermineApplyService.listMeetingRoomByTimeDetail(date, id);
    }

}

